You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: accept any realtime fallback host in REST requests - #751
When the realtime connection is established through a fallback host, REST requests on the same client can fail with ValueError: list.remove(x): x not in list.
Cause: the realtime connection manager tries every fallback host (5 by default), and the transport saves the one that connected in options.fallback_host (RTN17e). Http.get_hosts() then calls hosts.remove(host) on options.get_hosts(), which holds only the primary and the first http_max_retry_count (3 by default) fallbacks. If the saved host is one of the other two, remove raises before any request is sent.
Fix: put the saved host first, whether or not it was already in the list, and keep the list the same length, so http_max_retry_count still bounds the number of attempts. The order is unchanged when the host was already in the list. When it was not, the last fallback is dropped to make room.
Tests: added a unit test in test/unit/http_test.py that saves each of the 5 fallback hosts in turn. On main the 2 cases outside the REST list fail with the ValueError; all 5 pass with the change. test/uts/rest/unit and the realtime connection and client unit tests pass, and ruff check is clean.
Reproduction
fromably.pubsub.serverimportcreate_http_clientclient=create_http_client(token='foo')
client.options.fallback_host=client.options.get_fallback_hosts()[-1] # what the realtime transport doesclient.http.get_hosts() # ValueError
This PR was prepared with the help of an AI assistant (Claude); the change and tests are disclosed here as AI-assisted work.
Summary by CodeRabbit
Bug Fixes
Improved fallback host selection to avoid errors when a saved fallback host is absent and prevent duplicate hosts in the results.
Tests
Added coverage for fallback host ordering, uniqueness, and list size.
No actionable comments were generated in the recent review.
Walkthrough
Http.get_hosts now places the saved fallback host first, removes duplicates, and preserves the original host-list length. A parameterized unit test checks this behavior for all five realtime fallback hosts.
get_hosts prepends the saved host, removes duplicate occurrences, and limits the result to the original list length. The test checks ordering, list length, and duplicates for all five realtime fallback hosts.
This fixes REST requests failing when a realtime connection has fallen back to a host outside the REST retry list. The change is small, covered by a unit test for all five fallback hosts, and low risk to merge.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: REST requests now accept any realtime fallback host. The raw summary confirms Http.get_hosts now places the saved fallback host first instead of raising ValueError whe…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: REST requests now accept any realtime fallback host. The raw summary confirms Http.get_hosts now places the saved fallback host first instead of raising ValueError when it is absent, and a parameterized test covers all five fallback hosts. The title is specific and matches the changeset and the stated objectives.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Fix failing CI checks
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks the hosts in line The saved one hops to the front No duplicates crowd the list Five fallback hosts pass the test The list stays the same length Then off the rabbit goes to rest
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: b1d9eb4d-7a2f-4f15-8cde-64d61621170e
Commits
Reviewing files that changed from the base of the PR and between 2435510 and 4293f9a.
Files selected for processing: 2
ably/pubsub/request/http.py
test/unit/http_test.py
Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When the realtime connection is established through a fallback host, REST requests on the same client can fail with
ValueError: list.remove(x): x not in list.Cause: the realtime connection manager tries every fallback host (5 by default), and the transport saves the one that connected in
options.fallback_host(RTN17e).Http.get_hosts()then callshosts.remove(host)onoptions.get_hosts(), which holds only the primary and the firsthttp_max_retry_count(3 by default) fallbacks. If the saved host is one of the other two,removeraises before any request is sent.Fix: put the saved host first, whether or not it was already in the list, and keep the list the same length, so
http_max_retry_countstill bounds the number of attempts. The order is unchanged when the host was already in the list. When it was not, the last fallback is dropped to make room.Tests: added a unit test in
test/unit/http_test.pythat saves each of the 5 fallback hosts in turn. Onmainthe 2 cases outside the REST list fail with theValueError; all 5 pass with the change.test/uts/rest/unitand the realtimeconnectionandclientunit tests pass, andruff checkis clean.Reproduction
This PR was prepared with the help of an AI assistant (Claude); the change and tests are disclosed here as AI-assisted work.
Summary by CodeRabbit